home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-11-19 | 3.3 KB | 97 lines | [TEXT/MPS ] |
- /*
- File: TTaskSchedulerExample.cp
-
- Contains: This module shows an example of the TTaskScheduler class.
-
- Copyright: © 1993-1994 by Apple Computer, Inc., all rights reserved.
-
- */
-
- #include "TInitSLM.h" // the TInitSLM class and SLM include files
- #include "TTaskSchedulerExample.h"
-
- #include <Events.h>
- #include <Desk.h>
-
- ///————————————————————————————————————————————————————————————————————————————————————
- /// CONSTANTS
- ///————————————————————————————————————————————————————————————————————————————————————
-
- const unsigned kNumArcs = 360*2; // no. of arcs to draw
-
-
- ///————————————————————————————————————————————————————————————————————————————————————
- /// GLOBALS
- ///————————————————————————————————————————————————————————————————————————————————————
-
- static void init_toolbox( WindowPtr *window );
-
- /*————————————————————————————————————————————————————————————————————————————————————
- main
-
- This example shows the use of a TTaskScheduler. The TaskScheduler is going to sche-
- dule a FillArc operation on a given window. We allocate the window before hand,
- so the operation does not need to wory about it. TTaskScheduler is derived from
- from TPriorityScheduler, and operations are prioritised depending on the order
- of their scheduling. The TTaskScheduler does not have run method, it automatically
- gets called during SystemTask. When we call SystemTask all the operations will be
- processed. Note you can also call WaitNextEvent to get the TTaskScheduler to run.
- ————————————————————————————————————————————————————————————————————————————————————*/
-
- main()
- {
- TInitSLM initLibraryManager; // initialize the shared library manager
-
- if( initLibraryManager.Failed() ) // If we failed, let's go home
- return 1;
-
- WindowPtr window;
- init_toolbox( &window ); // initialize the tool box and our window
-
- TArcTask *thearcs[kNumArcs];
- TTaskScheduler taskscheduler; // create a TTaskScheduler
-
- // create and schedule kNumArcs TArcTasks
- for( short i=0; i<kNumArcs; i++ ) {
- // create a TArcTask
- thearcs[i] = new TArcTask( window, i );
-
- // Give each successive operation a lower priority then the previous
- // one so they are processed the ordered created. Actually if they
- // have the same priority they are processed in the ordered schedule,
- // so we could also have scheduled them in the opposite order.
- thearcs[i]->SetPriority( kNormalPriority + i*kToLowerPriority );
-
- // schedule the operation
- taskscheduler.Schedule( thearcs[i] );
- }
-
- SystemTask(); // call SystemTask so our operations will be processed
-
- DisposeWindow( window ); // close the window
-
- return 0;
- }
-
- /*————————————————————————————————————————————————————————————————————————————————————
- init_toolbox
-
- initalize the macintosh toolbox
- ————————————————————————————————————————————————————————————————————————————————————*/
- static void init_toolbox( WindowPtr *window )
- {
- // Initialize the macintosh toolbox
- MaxApplZone();
-
- InitGraf( (Ptr)&qd.thePort );
- InitFonts();
- InitWindows();
- InitDialogs( nil );
- InitCursor();
-
- // create a window to draw our arcs in
- Rect rect;
- *window = NewCWindow( 0L, &rect, "\p", false, documentProc,(WindowPtr)-1L, true, 0L );
- MoveWindow( *window, qd.screenBits.bounds.left+10, qd.screenBits.bounds.top+40, true );
- SizeWindow( *window, 100, 100, false );
- }